#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

priority_queue<ll, vector<ll>, greater<ll>> pq;

int q, p, x;
ll sum = 0;
int main() {
    cin >> q;
    while (q--) {
        cin >> p;
        if (p == 1) {
            cin >> x;
            pq.push(x - sum);
        } else if (p == 2) {
            cin >> x;
            sum += x;
        } else if (p == 3) {
            ll a = pq.top();
            pq.pop();
            cout << a + sum << endl;
        }
    }

    return 0;
}